package com.zr.userInfo.service.impl;

import com.zr.userInfo.mapper.UserInfoMapper;
import com.zr.userInfo.pojo.PaymentInformation;
import com.zr.userInfo.pojo.UserInfo;
import com.zr.userInfo.pojo.UserInfoAddVo;
import com.zr.userInfo.service.UserInfoService;
import com.zr.util.ResultBuildVo;
import com.zr.util.ResultVOBuilder;
import com.zr.util.ResultVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by Administrator on 2019/7/3.
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInforMapper;

    /**
     * 添加
     * @param userInfoAddVo
     * @return
     */
    @Override
    public ResultVo essentialInformation(UserInfoAddVo userInfoAddVo) {

        UserInfo userInfo = new UserInfo();
        Date nowDate = new Date();
        userInfo.setCreateTime(nowDate);
        userInfo.setCreateName("小明");
        userInfo.setUpdateTime(nowDate);
        userInfo.setUpdateName("小明");
        BeanUtils.copyProperties(userInfoAddVo, userInfo);
//        userInfoAddVo.add(userInfo);

        userInforMapper.essentialInformation(userInfo);
        return ResultVOBuilder.success(userInfo);
    }

    @Override
    public ResultVo queryLoginId(Integer loginId) {
        if (loginId == 0){
            return ResultVOBuilder.error("注册信息的ID不存在","500");
        }
        UserInfoAddVo userInfoAddVo = userInforMapper.queryLoginId(loginId);
        return ResultVOBuilder.success(userInfoAddVo);
    }

    @Override
    public ResultVo queryByPid(Integer id) {
        PaymentInformation paymentInformation = userInforMapper.queryByPid(id);
        return ResultBuildVo.success(paymentInformation);
    }
}
